package com.tcc.fastline.Criptografia;

import java.util.Hashtable;

public final class Criptografia {

	private final static Hashtable<Integer, String> dicionarioCriptografia = CriarDicionarioCriptografia();
	private final static Hashtable<String, String> dicionarioDecriptografia = CriarDicionarioDecriptografia();

	public static String Criptografar(String senha) {
		String resposta = "";

		char[] caracteres = senha.toCharArray();

		for (char c : caracteres) {
			resposta = resposta
					+ dicionarioCriptografia.get(Character.getNumericValue(c));
		}

		return resposta;
	}

	public static String Decriptografar(String senha){
		String resposta = "";

		char[] caracteres = senha.toCharArray();

		for (char c : caracteres) {
			resposta = resposta + dicionarioDecriptografia.get(Character.getNumericValue(c));
		}

		return resposta;
	}

	private static Hashtable<Integer, String> CriarDicionarioCriptografia() {
		Hashtable<Integer, String> hash = new Hashtable<Integer, String>();

		hash.put(0, "K");
		hash.put(1, "H");
		hash.put(2, "F");
		hash.put(3, "D");
		hash.put(4, "A");
		hash.put(5, "M");
		hash.put(6, "Z");
		hash.put(7, "P");
		hash.put(8, "Q");
		hash.put(9, "W");

		return hash;
	}

	private static Hashtable<String, String> CriarDicionarioDecriptografia() {
		Hashtable<String, String> hash = new Hashtable<String, String>();

		hash.put("K", "0");
		hash.put("H", "1");
		hash.put("F", "2");
		hash.put("D", "3");
		hash.put("A", "4");
		hash.put("M", "5");
		hash.put("Z", "6");
		hash.put("P", "7");
		hash.put("Q", "8");
		hash.put("W", "9");

		return hash;
	}
}
